<template>
	<el-col :span="componentModel.col*6" v-show="visible">
		<el-row>
			<el-col :span="8" class="field-label-div" v-if="!componentModel.noLabel">
				<label class="field-label">{{componentModel.label}}</label>
			</el-col>
			<el-col :span="componentModel.fieldcol">
				<el-time-picker  placeholder="任意时间点" v-model="vue_model" @change="onChangeHandler"  :readonly="readonly" size="mini"> </el-time-picker>
			</el-col>
		</el-row>
	</el-col>
</template>

<script>
	import {sendComponentValueChangeRequest} from '@/utils/requestUtils.js';
	import utils from '@/utils/utils.js';
	export default {
		name:"TimeComponent",
		props:["componentModel","scope"],
		data() {
			return {
				vue_model:null,
				visible:true,
				readonly:false,
				label: "",
			}
		},
		inject:['children'],
		mounted() {
			this.children.push(this);
		},beforeUnmount() {
			utils.removeArrayElement(this.children,this);
		},methods:{
			getValue(){
				if(this.vue_model==null||this.vue_model==""){
					return "";
				}else{
					return this.vue_model.getHours()+":"+this.vue_model.getMinutes()+":"+this.vue_model.getSeconds();
				}
				
			},setProp(prop) {
				for(var k in prop){
					if(k=="value"){
						if(prop[k]==null){
							this.vue_model=null;
						}else{
							var timeArray=prop[k].split(":");
							this.vue_model=new Date(2020,3, 25, 
							parseInt(timeArray[0]), parseInt(timeArray[1]), parseInt(timeArray[2]));
						}
					}else if(k=="visible"){
						this.visible=prop[k];
					}else if(k=="readonly"){
						this.readonly=prop[k];
					}else if(k=="label"){
						this.label = prop[k];
					}
				}
			},
			onChangeHandler() {
				if (this.scope != undefined) {
					this.$emit("onValueChange", this);
					return;
				}
				sendComponentValueChangeRequest(this);
			}
		}
	}
</script>

<style>
</style>
